package cn.edu.scau.cmi.tangqingning.multiton;

import java.util.ArrayList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class MultitonController {

	@FXML
    private TextArea textArea;

    @FXML
    private TextField textField;

    ArrayList<Marshal> marshalArrayList;

    @FXML
    void onCreateClick(ActionEvent event) {
    	if(marshalArrayList != null && marshalArrayList.size() == 10) {
    		this.textArea.setText("创建失败，新增元帅个数已达到最大！");
    		return;
    	}
    	marshalArrayList = Marshal.getInstance(this.textField.getText());
		this.textArea.setText("创建成功，新增元帅为：" + this.textField.getText());
    }

    @FXML
    void onShowClick(ActionEvent event) {
    	if(marshalArrayList != null) {
    		StringBuilder s = new StringBuilder();
    		s.append("当前元帅是：");
    		int i = 0;
    		for(i = 0; i < marshalArrayList.size(); i++){
                if(i < marshalArrayList.size() - 1) {
                    s.append(marshalArrayList.get(i).getName() + "、");
                } else {
                	s.append(marshalArrayList.get(i).getName());
                }
            }
    		this.textArea.setText(s.toString());
    	} else {
    		this.textArea.setText("当前无元帅");
    	}
    }
}

